package tech.aistar.service.impl.dynamic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.entity.dynamic.Picture;
import tech.aistar.mapper.IPrisePicMapper;
import tech.aistar.mapper.PictureMapper;
import tech.aistar.service.IPictureVoService;
import tech.aistar.vo.PictureVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Ace
 * @version 1.0
 * @descriiption:本类用来演示:
 * @date 2019/10/14 0014.
 */
@Service
public class PictureVoServiceImpl implements IPictureVoService {
    @Autowired
    private PictureMapper pictureMapper;
    @Autowired
    private IPrisePicMapper prisePicMapper;

    @Override
    public List<PictureVo> findAll(Integer uid) {
        List<Picture> pictureList=pictureMapper.findAll();
        List<PictureVo> pictureVoList=new ArrayList<>();
        for(Picture picture:pictureList){
            PictureVo pictureVo=new PictureVo();
            pictureVo.setPicture(picture);
            pictureVo.setPriseCount(prisePicMapper.countPriseByPic(picture.getPicId()));
            if (uid==null){
                pictureVo.setIsmyprise(false);
            }else {
                pictureVo.setIsmyprise(prisePicMapper.findByPidByUid(picture.getPicId(),uid)==null?false:true);
            }
            pictureVoList.add(pictureVo);
        }
        return pictureVoList;
    }
}
